
import {mapGetters} from 'vuex';
import moment from 'moment';
import {ACCOUNTURL,ADCONVERT,ADVER,ALLCREATE,SITEURL,THIRDSITE,DMPURL} from "@/services/api";
import {ajaxparems,ajaxrequest} from "@/services/ajaxrequest";
var columnslabel = [
  {
	title: '#',
	width:30,
	fixed: 'left',
	scopedSlots: { customRender: 'keyDemo' },
	
  },{
	title: '广告计划',
	fixed: 'left',
	width:195,
	scopedSlots: { customRender: 'planDemo' },
	filterMultiple:true,
  },
  {
	title: '推广渠道',
	width:200,
	fixed: 'left',
	scopedSlots: { customRender: 'channelDemo' },
  },
  {
	scopedSlots: { customRender: 'adverDemo' },
	slots: { title: 'adverTitle' },
	filterMultiple:true,
  },{
	slots: { title: 'directionalTitle' },
    scopedSlots: { customRender: 'directionalDemo' },
  },{
	slots: { title: 'crowdTitle' },
    scopedSlots: { customRender: 'crowdDemo' },
  },{
	slots: { title: 'originTitle' },
	scopedSlots: { customRender: 'originDemo' },
  },{
    slots: { title: 'converTitle' },
    scopedSlots: { customRender: 'converDemo' },
  },{
	slots: { title: 'pageTitle' },
	// title:'链接详情',
	width:200,
    scopedSlots: { customRender: 'pageDemo' },
  },{
	title: '操作',
	fixed: 'right',
	width: 100,
	scopedSlots: { customRender: 'action' },
  },
];
var datalist = [];
var listbox = [];

var onedata = [];
var twodata = [];
export default {
    created(){
		this.listNew();
		this.newtime();
	},
	beforeCreate() {
		this.form = this.$form.createForm(this);
		this.form2 = this.$form.createForm(this);
		this.form3 = this.$form.createForm(this);
		this.form4 = this.$form.createForm(this);
		this.form5 = this.$form.createForm(this);
		this.form6 = this.$form.createForm(this);
		this.form9 = this.$form.createForm(this);
    },
	data() {
		return {
			spinning:true,
			columnslabel,
			datalist,
			timenum:'now',
			nowtime:'',
			advertisers:[],
			type:1,
			scene:1,
			num:1,
			logging:false,
			listbox,
			confirmLoading:false,
			onemodal:false,
			twomodal:false,
			threemodal:false,
			fivemodal:false,
			sixmodal:false,
			sixmodalxz:false,
			sevenmodal:false,
			onedata,
			twodata,
			threedata:[],
			conversion:[],
			ruleval:'a',
			tworuleval:'a',
			threeruleval:'1',
			fiveruleval:'a',
			useloading:false,

			account_id:'',
			account_n:'',
			account_v:'',
			checked: false,
			thisnum:'0',

			visibleld:false,
			useldylsit:[],
			externalurl:'',
			name:'',
			campaignid:'',//广告组id
			audienceid:'',//定向ID
			creativesid:'',//创意组ID
			convertid:'',//转化ID
			loggingld:false,
			nametext:'',
			twotext:'',
			threetext:'',
			mockData: [],
      		targetKeys: [],

			allSchool: [],//定向人群包
			allTeam: [],  //人群包列表
			leader:[],// 排除人群包
			schoolsNames: [],   //定向人群 选中的
			teamName: [],   //人群包  选中的
			teamLeader: [],   //排除人群  选中的
			
		};
	},
	mounted(){
		// this.getMock();
	},
	props: ["schoolInfo","teamInfo","leaderInfo"],
	watch: {
		schoolInfo(val) {   //  编辑时用来回显，添加时的默认数据
		  this.schoolInfo = val;
		  this.allSchool = val;
		},
		teamInfo(val){   //  编辑时用来回显
		  this.teamInfo = val;
		  this.allTeam=val;
		},
		leaderInfo(val){   //  编辑时用来回显
		  this.leaderInfo=val;
		  this.leader=val;
		},
	},
  	methods:{
		moment,
		//全选
		onCheckAllChange(n,e,num){
			if(num ==1){
				// 广告组
				this.datalist[n].list.forEach((res)=>{
					res.one.is_check = e.target.checked;
				})
				this.datalist[n].advercheckAll = e.target.checked;
			}else if(num ==2){
				//定向
				this.datalist[n].list.forEach((res)=>{
					res.two.is_check = e.target.checked;
				})
				this.datalist[n].audiencecheckAll = e.target.checked;
			}else if(num ==3){
				//创意
				this.datalist[n].list.forEach((res)=>{
					res.three.is_check = e.target.checked;
				})
				this.datalist[n].creativecheckAll = e.target.checked;
			}else if(num ==4){
				//转化
				this.datalist[n].list.forEach((res)=>{
					res.two.is_checks = e.target.checked;
				})
				this.datalist[n].conversioncheckAll = e.target.checked;
			}else if (num ==7){
				//人群包
				this.datalist[n].list.forEach((res)=>{
					res.two.crowdcheck = e.target.checked;
				})
				this.datalist[n].crowdcheckAll = e.target.checked;
			}else if(num ==5){
				//链接
				this.datalist[n].list.forEach((res)=>{
					res.two.urlcheck = e.target.checked;
				})
				this.datalist[n].pagecheckAll = e.target.checked;
			}
		
		},
		//单选
		onadvercheck(n,i,e,num){
			if(num ==1){
				this.datalist[n].list[i].one.is_check = e.target.checked
			}else if(num ==2){
				this.datalist[n].list[i].two.is_check = e.target.checked
			}else if(num ==3){
				this.datalist[n].list[i].three.is_check = e.target.checked
			}else if(num ==4){
				this.datalist[n].list[i].two.is_checks = e.target.checked
			}else if(num ==5){
				this.datalist[n].list[i].two.urlcheck = e.target.checked
			}else if(num ==7){
				this.datalist[n].list[i].two.crowdcheck = e.target.checked
			}
		},
		//点击批量选择
		alladverset(n,v,vals,num,ids,account_id){
			this.thisnum = num;
			this.account_id = account_id;
			var storage=window.localStorage;
			if(num ==1){
			//广告组
				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].one.is_check){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}

				var infoone = storage.getItem("one");
				var one = JSON.parse(infoone);
				if(one.scene ==3){
					one.list.forEach((res)=>{
						if(account_id == res.advertiser_id){
							this.onedata = res.campaignlist;
							this.onemodal = true;
						}
					})
				}else{
					var accountparems = {"filtering":[
						// {"field":'account_id',"operator":'EQUALS',"value":account_id},
						{"field":'id',"operator":'IN',"value":one.campaignlist[v]},
					]};
					ajaxparems(ADVER, accountparems).then((res) => {
						var result = res.data;
						if (result.code == "SUCCESS") {
							this.onedata = result.data.list;
							this.onemodal = true;
						} else {
							this.$message.error(result.message, 3);
						}
					});
				}

				// this.form2.setFieldsValue({
				// 	rule:'b',
				// })
				// this.ruleval = 'b';
				
			}else if(num ==2){
			//定向
				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].two.is_check){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}

				var infotwo = storage.getItem("two");
				var two = JSON.parse(infotwo);
				this.twodata = two.audience;
				this.twomodal = true;
				//表单默认选中
				// this.form3.setFieldsValue({
				// 	twogroup:ids,
				// })
			}else if(num ==3){
			//创意
				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].three.is_check){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}

				var infothree = storage.getItem("three");
				var three = JSON.parse(infothree);
				this.threedata = three.creatives;
				this.threemodal = true;
				//表单默认选中
				// this.form4.setFieldsValue({
				// 	threegroup:ids,
				// })
			}else if(num ==4){
				//转化
				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].two.is_checks){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}

				var convert = {"filtering":[{"field":'account_id',"operator":'EQUALS',"value":account_id}]};
				//转化目标
				ajaxparems(ADCONVERT,convert).then((res) => {
					var result = res.data;
					if(result.code =="SUCCESS"){
					  this.conversion = result.data;
					  this.fivemodal = true;
					}else{
					  this.$message.error(result.message,3);
					}
				});
			}else if(num ==7){
				//人群
				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].two.crowdcheck){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}
				
				this.sevenmodal = true;
			}else if(num ==5){

				for (let i = 0; i < this.datalist[n].list.length; i++) {
					if(this.datalist[n].list[i].two.urlcheck){
						break;
					}
					if(i === this.datalist[n].list.length -1) {
						this.$message.error('至少选择一项');
						return;
					}
				}
				this.sixmodal = true;

			}
			this.account_n = n;
		},

		//人群包功能
		async toRightTeam() {
			//取消选中定向人群
			let moveName= await this.matching(this.allSchool,this.schoolsNames);
			let allArr= await this.myFilter(this.allSchool,moveName);
			this.allSchool = allArr;
			for(let i=0;i<moveName.length;i++){
			  this.allTeam.push(moveName[i])
			}
			this.schoolsNames=[];
			await this.putParentsTeams();
		},
		async toLeftSchools() {
			//选择定向人群
			let moveName= await this.matching(this.allTeam,this.teamName);
			let allArr =await this.myFilter(this.allTeam,moveName);
			this.allTeam = allArr;
			for(let i=0;i<moveName.length;i++){
			  this.allSchool.push(moveName[i])
			}
			this.teamName=[];
			await this.putParentsTeams();
		},
		async toRightLeader() {
			//取消排除人群
			let moveName= await this.matching(this.allTeam,this.teamName);
			let allArr =await this.myFilter(this.allTeam,moveName);
			this.allTeam = allArr;
			for(let i=0;i<moveName.length;i++){
			  this.leader.push(moveName[i])
			}
			this.teamName=[];
			await this.putParentsTeams();
		},
		async toLeftTeam() {
			//选择排除人群
			let moveName= await this.matching(this.leader,this.teamLeader);
			let allArr =await this.myFilter(this.leader,moveName);
			this.leader = allArr;
			for(let i=0;i<moveName.length;i++){
			  this.allTeam.push(moveName[i])
			}
			this.teamLeader=[];
			await this.putParentsTeams();
		},

		// 过滤 相同选项
		async myFilter(allArr, selArr) {

			console.log(selArr);
			// let ary03 = [];
			for (let i = 0; i < allArr.length; i++) {
			  for (let j = 0; j < selArr.length; j++) {
				if (allArr[i].custom_audience_id == selArr[j].custom_audience_id) {
				  allArr.splice(i,1);
				}
			  }
			}
			return allArr;
		},
		//  匹配 移动的 选项
		async matching(allArr, matchArr) {
			let matArr = [];
			for (let i = 0; i < allArr.length; i++) {
			  for (let j = 0; j < matchArr.length; j++) {
				if (allArr[i].custom_audience_id == matchArr[j]) {
				  matArr.push(allArr[i]);
				}
			  }
			}
			return matArr;
		},
		//    向父组件传人群名称 和人群id   由于这是单独的一个穿梭框组件，数据会和父组件里面的动态绑定，提交按钮也在父组件，所以需要此步骤，
		async putParentsTeams() {
			this.$emit('teamNames', this.allTeam,this.leader);
		},

		onuseldy(){
			this.useloading = true;
			this.loggingld = true;
			//落地页选择已有
			ajaxrequest(this.account_id, SITEURL,"").then((res) => {
				var result=res.data;
				if(result.code =="SUCCESS"){
					this.visibleld = true;
					this.loggingld = false;
					this.useloading = false;
				  this.useldylsit = result.data.list;
				}else{
					this.useloading = false;
				  this.$message.error(result.message,3);
				}
			})
		},
		onlanpage(e){
			//落地页筛选
			if(e ==1){
				// 橙子建站落地页
				ajaxrequest(this.account_id, SITEURL,"").then((res) => {
					var result=res.data;
					if(result.code =="SUCCESS"){
					  this.useldylsit = result.data.list;
					}else{
					  this.$message.error(result.message,3);
					}
				})
			}else{
				// 第三方落地页
				ajaxrequest(this.account_id, THIRDSITE,"").then((res) => {
					var result=res.data;
					if(result.code =="SUCCESS"){
					  this.useldylsit = result.data.list;
					}else{
					  this.$message.error(result.message,3);
					}
				})
			}
		},
	
		resetldForm(){
			//落地页重置
			this.form6.resetldForm();
		},
	
		serachldy(){
			this.form6.validateFieldsAndScroll((err, values) => {
				if(!err){
					var paremsdata = [];
					if(values['name'] !=undefined){
						var numReg = /^[0-9]*$/
						var numRe = new RegExp(numReg)
						if (!numRe.test(values['name'])) {
							paremsdata.push({"siteId":values['name']})
						}else{
							paremsdata.push({"search":values['name']})
						}
					}
				}
	
				var parems = {"filtering":paremsdata};
				if(values['lanpage'] ==2){
					// 第三方落地页
					ajaxrequest(this.account_id, THIRDSITE,parems).then((res) => {
						var result=res.data;
						if(result.code =="SUCCESS"){
						  this.useldylsit = result.data.list;
						}else{
						  this.$message.error(result.message,3);
						}
					})
				}else{
					// 橙子建站落地页
					ajaxrequest(this.account_id, SITEURL,parems).then((res) => {
						var result=res.data;
						if(result.code =="SUCCESS"){
						  this.useldylsit = result.data.list;
						}else{
						  this.$message.error(result.message,3);
						}
					})
				}
				
			})
		},
		onuse(item){
			//选择已有
			item = Object.assign({},item, {url:'https://www.chengzijianzhan.com/tetris/page/'+item.siteId+'/'});
			this.externalurl = item;
			this.visibleld = false;
			this.external = false;

			this.form6.setFieldsValue({
				external_url:item.url,
				external:item
			})

		},
		ldyCancel(){
			this.visibleld = false;
		},

		onaudience(){
			// 广告计划名称选择
		},
		oncampaign(n,v,vals,num,ids,account_id){
			// 点击选择对应广告组
			this.thisnum = num;
			// var account_id = this.datalist[n].account_id;//获取广告账户
			this.account_id = account_id;

			var storage=window.localStorage;
			//获取广告组
			if(num ==1){
				this.campaignid= ids;
				var infoone = storage.getItem("one");
				var one = JSON.parse(infoone);
				if(one.scene ==3){
					one.list.forEach((res)=>{
						if(account_id == res.advertiser_id){
							this.onedata = res.campaignlist;
							this.onemodal = true;
						}
					})
				}else{
					var accountparems = {"filtering":[
						// {"field":'account_id',"operator":'EQUALS',"value":account_id},
						{"field":'id',"operator":'IN',"value":one.campaignlist[v]},
					]};
					ajaxparems(ADVER, accountparems).then((res) => {
						var result = res.data;
						if (result.code == "SUCCESS") {
							this.onedata = result.data.list;
							this.onemodal = true;
						} else {
							this.$message.error(result.message, 3);
						}
					});
				}

				this.datalist[n].list.map(v=>{
					v.one.is_check = false
				})
				this.datalist[n].advercheckAll = false;
				this.datalist[n].list[v].one.is_check = true;

				//表单默认选中
				this.form2.setFieldsValue({
					advergroup:ids,
				})

			// 获取广告定向
			}else if(num ==2){
				this.audienceid= ids;
				var infotwo = storage.getItem("two");
				var two = JSON.parse(infotwo);
				this.twodata = two.audience;
				this.twomodal = true;
				//表单默认选中
				this.form3.setFieldsValue({
					twogroup:ids,
				})
				this.datalist[n].list.map(v=>{
					v.two.is_check = false
				})
				this.datalist[n].audiencecheckAll = false;
				this.datalist[n].list[v].two.is_check = true;

			}else if(num ==3){
				this.creativesid= ids;
				var infothree = storage.getItem("three");
				var three = JSON.parse(infothree);
				this.threedata = three.creatives;
				this.threemodal = true;
				//表单默认选中
				this.form4.setFieldsValue({
					threegroup:ids,
				})
				this.datalist[n].list.map(v=>{
					v.three.is_check = false
				})
				this.datalist[n].creativecheckAll = false;
				this.datalist[n].list[v].three.is_check = true;
			}else if(num ==4){
				this.convertid = ids;
				var convert = {"filtering":[{"field":'account_id',"operator":'EQUALS',"value":account_id}]};
				//转化目标
				ajaxparems(ADCONVERT,convert).then((res) => {
					var result = res.data;
					if(result.code =="SUCCESS"){
					  this.conversion = result.data;
					  this.fivemodal = true;
					}else{
					  this.$message.error(result.message,3);
					}
				});
				//表单默认选中
				this.form5.setFieldsValue({
					fivegroup:ids,
				})
				this.datalist[n].list.map(v=>{
					v.two.is_checks = false
				})
				this.datalist[n].conversioncheckAll = false;
				this.datalist[n].list[v].two.is_checks = true;
			}else if(num ==5){
				this.sixmodal = true;
				this.datalist[n].list.map(v=>{
					v.two.urlcheck = false
				})
				this.datalist[n].list[v].two.urlcheck = true;
				this.form6.setFieldsValue({
					external_url:'',
					external:'',
				})

			}else if(num ==6){
				this.sixmodalxz = true;
				this.form6.setFieldsValue({
					download_url:'',
				})
			}else if(num ==7){

				console.log(this.datalist[n].list[v]);

				if(this.datalist[n].list[v].two.audiencelist.audience.retargeting_tags_include.length >0){
					// console.log(1);
					this.allSchool = JSON.parse(JSON.stringify(this.datalist[n].list[v].two.audiencelist.audience.retargeting_tags_include));
					this.leader = JSON.parse(JSON.stringify(this.datalist[n].list[v].two.audiencelist.audience.retargeting_tags_exclude));
					// var arry=([...this.datalist[n].list[v].two.audiencelist.audience.retargeting_tags_include,...this.datalist[n].list[v].two.audiencelist.audience.retargeting_tags_exclude])
					// for (let i = 0; i < this.allTeam.length; i++) {
					// 	for (let b = 0; b < arry.length; b++) {
					// 		if(this.allTeam[i].custom_audience_id == arry[b].custom_audience_id){
					// 			this.allTeam.splice(this.allTeam.indexOf(arry[b].custom_audience_id),1)
					// 		}
					// 	}
					// }			
					// var new_arr = [];
					// var arr = this.isExistArr(this.allTeam,arry,new_arr);
					// console.log(arr);

				}else{
					console.log(2);
					this.allSchool= [];
					this.leader= [];

					this.dmplist();
				}

				this.datalist[n].list.map(v=>{
					v.two.crowdcheck = false
				})
				this.datalist[n].crowdcheckAll = false;
				this.datalist[n].list[v].two.crowdcheck = true;
				this.sevenmodal = true;
			}
			console.log(this.datalist);
			this.account_n = n;
			this.account_v = v;
			console.log(this.account_n,this.account_v);
		},

		handleOk(){
			//弹窗确定框
			var num = this.thisnum;
			this.confirmLoading = true;
			// 确定广告组
			var reg = '';
			var name = '';
			if(num ==1){
				this.form2.validateFieldsAndScroll((err, values) => {
					if(!err){
						console.log(values);
						// var accountparems= {};
						if(this.ruleval =='a'){
							this.datalist[this.account_n].list.forEach((res,index)=>{
								if(res.one.is_check == true){
									this.datalist[this.account_n].list[index].one.campaignlist = values['advergroup'];
								}
							})
							this.onemodal = false;
							this.confirmLoading = false;
						}else{
							this.datalist[this.account_n].list.forEach((res,index)=>{
								if(res.one.is_check == true){
									console.log(values['advergroups'][values['advergroups'].length-1]);
									this.datalist[this.account_n].list[index].one.campaignlist = values['advergroups'][index] !==undefined ?values['advergroups'][index] : values['advergroups'][0];
								}
							})
							this.onemodal = false;
							this.confirmLoading = false;
						}
					}else{
						this.$message.error("请选择广告组",3);
						this.confirmLoading = false;
						return;
					}
				})
			}else if(num ==2){
			//确定定向
				this.form3.validateFieldsAndScroll((err, values) => {
					if(!err){
						var storage=window.localStorage;
						var infotwo = storage.getItem("two");
						var two = JSON.parse(infotwo);
						if(this.tworuleval =='a'){
						
							this.datalist[this.account_n].list.forEach((res,index)=>{
								name = this.datalist[this.account_n].list[index].two.name;
								if(res.two.is_check == true){
									this.datalist[this.account_n].list[index].two.audiencelist = values['twogroup'];
									two.audience.forEach((res)=>{
										if(values['twogroup'].id == res.id){
											var twotext = this.datalist[this.account_n].list[index].two.twotext;
											if(twotext !=''){
												if(this.datalist[this.account_n].list[index].two.name.includes(twotext)){
													reg = this.newregexp(twotext,"g");
													this.datalist[this.account_n].list[index].two.name=name.replace(reg,res.name);
												}
											}
											this.datalist[this.account_n].list[index].two.twotext = res.name;
											this.datalist[this.account_n].list[index].two.audiencelist = res;
										}
									})
								}
							})
							// two.audience.forEach((res)=>{
							// 	if(values['twogroup'] == res.id){
							// 			var twotext = this.datalist[this.account_n].list[this.account_v].two.twotext;
							// 			if(twotext !=''){
							// 				if(this.datalist[this.account_n].list[this.account_v].two.name.includes(twotext)){
							// 					reg = this.newregexp(twotext,"g");
							// 					this.datalist[this.account_n].list[this.account_v].two.name=name.replace(reg,res.name);
							// 				}
							// 			}
							// 		this.datalist[this.account_n].list[this.account_v].two.twotext = res.name;
							// 		this.datalist[this.account_n].list[this.account_v].two.audiencelist = res;
							// 	}
							// })
							this.confirmLoading = false;
							this.twomodal = false;
							this.checked = false;
						}else{
							this.datalist[this.account_n].list.forEach((res,index)=>{
								if(res.two.is_check == true){
									this.datalist[this.account_n].list[index].two.audiencelist = values['twogroups'][index] !==undefined ?values['twogroups'][index] : values['twogroups'][0];
										// var iitem = values['twogroups'][index] !==undefined ?values['twogroups'][index] : values['twogroups'][0];

										// console.log(values['twogroups']);
										// two.audience.forEach((ii)=>{
										// 	values['twogroups'].forEach((res)=>{
										// 		if(ii.id == res.id){
										// 			var twotext = this.datalist[this.account_n].list[index].two.twotext;
										// 			if(twotext !=''){
										// 				if(this.datalist[this.account_n].list[index].two.name.includes(twotext)){
										// 					reg = this.newregexp(twotext,"g");
										// 					this.datalist[this.account_n].list[index].two.name=name.replace(reg,res.name);
										// 				}
										// 			}
										// 			this.datalist[this.account_n].list[index].two.twotext = res.name;
										// 			this.datalist[this.account_n].list[index].two.audiencelist = res;
										// 		}
										// 	})
										// });

									// two.audience.forEach((res)=>{
									// 	var iitem = values['twogroups'][index] !==undefined ?values['twogroups'][index] : values['twogroups'][0];
									// 	if(iitem.id == res.id){
									// 		var twotext = this.datalist[this.account_n].list[index].two.twotext;
									// 		if(twotext !=''){
									// 			if(this.datalist[this.account_n].list[index].two.name.includes(twotext)){
									// 				reg = this.newregexp(twotext,"g");
									// 				this.datalist[this.account_n].list[index].two.name=name.replace(reg,res.name);
									// 			}
									// 		}
									// 		this.datalist[this.account_n].list[index].two.twotext = res.name;
									// 		this.datalist[this.account_n].list[index].two.audiencelist = res;
									// 	}
									// })
								}
							})
							this.confirmLoading = false;
							this.twomodal = false;
							this.checked = false;
						}
					}else{
						this.$message.error("请选择定向",3);
						this.confirmLoading = false;
						return;
					}
				})

			}else if(num ==3){
				//确定创意
				this.form4.validateFieldsAndScroll((err, values) => {
					if(!err){
						var storage=window.localStorage;
						var infothree = storage.getItem("three");
						var three = JSON.parse(infothree);
						if(this.threeruleval =='1'){
							this.datalist[this.account_n].list.forEach((res,index)=>{
								name = this.datalist[this.account_n].list[index].two.name;
								if(res.three.is_check == true){
									this.datalist[this.account_n].list[index].three.creativeslist = values['threegroup'];
									three.creatives.forEach((res)=>{
										if(values['threegroup'].name == res.name){
											var twotext = this.datalist[this.account_n].list[index].three.twotext;
											if(twotext !=''){
												if(this.datalist[this.account_n].list[index].two.name.includes(twotext)){
													reg = this.newregexp(twotext,"g");
													this.datalist[this.account_n].list[index].two.name=name.replace(reg,res.name);
												}
											}
											this.datalist[this.account_n].list[index].three.twotext = res.name;
											this.datalist[this.account_n].list[index].three.creativeslist = res;
										}
									})
								}
							})
							this.confirmLoading = false;
							this.threemodal = false;
							this.checked = false;
						}else{
							this.datalist[this.account_n].list.forEach((res,index)=>{
								if(res.three.is_check == true){
									this.datalist[this.account_n].list[index].three.creativeslist = values['threegroups'][index] !==undefined ?values['threegroups'][index] : values['threegroups'][0];
								}
							})
							this.confirmLoading = false;
							this.threemodal = false;
							this.checked = false;
						}
					}else{
						this.$message.error("请选择创意",3);
						this.confirmLoading = false;
						return;
					}
				})
				
			}else if(num ==4){
			// 确定转化目标
				this.form5.validateFieldsAndScroll((err, values) => {
					if(!err){
						if(this.fiveruleval =='a'){
							this.datalist[this.account_n].list.forEach((res,index)=>{
								name = this.datalist[this.account_n].list[index].two.name;
								if(res.two.is_checks == true){
									this.datalist[this.account_n].list[index].two.conversion = values['fivegroup'];
									if(this.datalist[this.account_n].list[index].two.name.includes('{转化名称}')){
										reg = this.newregexp("{转化名称}","g");
										this.datalist[this.account_n].list[index].two.name=name.replace(reg,values['fivegroup'].name); 
									}else{
										var nametext = this.nametext;
										if(nametext !=''){
											if(this.datalist[this.account_n].list[index].two.name.includes(nametext)){
												reg = this.newregexp(nametext,"g");
												this.datalist[this.account_n].list[index].two.name=name.replace(reg,values['fivegroup'].name); 
											}
										}
									}
									this.nametext = values['fivegroup'].name;
								}
							})
							this.confirmLoading = false;
							this.fivemodal = false;
							this.checked = false;
						}else{
							this.datalist[this.account_n].list.forEach((res,index)=>{
								if(res.two.is_checks == true){
									this.datalist[this.account_n].list[index].two.conversion = values['fivegroups'][index] !==undefined ?values['fivegroups'][index] : values['fivegroups'][0];
								}
							})
							this.confirmLoading = false;
							this.fivemodal = false;
							this.checked = false;

						}
					}else{
						this.$message.error("请选择转化配置",3);
						this.confirmLoading = false;
						return;
					}
				})
			}else if(num ==5){
				//确定落地页链接详情
				this.form6.validateFieldsAndScroll((err, values) => {
					if(!err){

						console.log(values);

						this.datalist[this.account_n].list.forEach((res,index)=>{
							if(res.two.urlcheck == true){
								this.datalist[this.account_n].list[index].two.external_url = values['external_url'];
								this.datalist[this.account_n].list[index].two.externalname = values['external']['name'] ? values['external']['name']:values['external_url'] ;
								this.datalist[this.account_n].list[index].two.externalurl = values['external'];
							}
						})

						this.form6.setFieldsValue({
							external:'',
							external_url:'',
						})
						this.sixmodal = false;
						this.checked = false;
						this.confirmLoading = false;
					}
				})
				
			}else if(num ==6){
				this.form6.validateFieldsAndScroll((err, values) => {
					if(!err){
						if(values['download_url'] ==''){
							this.message.error('请输入应用下载链接');
							return;
						}
						this.confirmLoading = false;
						this.datalist[this.account_n].list[this.account_v].two.external_url = values['download_url'];
						this.datalist[this.account_n].list[this.account_v].two.externalname = values['external']['name'] ?values['external']['name']:values['download_url'];
						this.sixmodalxz = false;
					}
				})
			}else if(num ==7){

				
				for (let i = 0; i < this.datalist[this.account_n].list.length; i++) {
					// var datas = [];
					if(this.datalist[this.account_n].list[i].two.crowdcheck == true){
						// var data = [...this.allSchool];//每次循环的时候，新建对象
						// datas.push(data);
						// console.log(data,'3333333');
						this.datalist[this.account_n].list[i].two.audiencelist.audience.retargeting_tags_include = [].concat(this.allSchool);
					}
				}

				// console.log(datas);

				// this.datalist[this.account_n].list.forEach((res,index)=>{
				// 	if(res.two.crowdcheck == true){
				// 		// console.log(index)
				// 		// console.log(JSON.parse(JSON.stringify(this.allSchool)));
				// 		console.log(Object.assign({}, this.allSchool));
				// 		this.datalist[this.account_n].list[index].two.audiencelist.audience.retargeting_tags_include = JSON.parse(JSON.stringify(this.allSchool)); //定向
				// 		this.datalist[this.account_n].list[index].two.audiencelist.audience.retargeting_tags_exclude = JSON.parse(JSON.stringify(this.leader));//排除
				// 	}
				// })
				// console.log(this.datalist[this.account_n].list);
				this.sevenmodal = false;
				this.confirmLoading = false;
			}
		},
		
		isExistArr(arr1,arr2,new_arr){   // arr1原数组   arr2 要除去的数组   new_arr新的空数组
			arr1.forEach(function(item){

				console.log(item.custom_audience_id);

				console.log(arr2);

				if(arr2.indexOf(item.custom_audience_id) == -1){
					new_arr.push(item);
				}
			})
			return new_arr;
		},
		onexternal(e){
			console.log(e.target.value);
		},
		onrule(e){
			//广告组配置规则
			this.ruleval = e.target.value;
		},
		ontworule(e){
			//定向包配置规则
			this.tworuleval = e.target.value;
		},
		onthreerule(e){
			//定向包配置规则
			this.threeruleval = e.target.value;
		},
		onfiverule(e){
			// 转化配置规则
			this.fiveruleval = e.target.value;
		},
		oneSearch(e){
			// 模糊查找广告组
			var account_id = this.account_id;
			var accountparems = {"filtering":[
				{"field":'account_id',"operator":'EQUALS',"value":account_id},
				{"field":'name',"operator":'LINK',"value":e},
			]};
			ajaxparems(ADVER, accountparems).then((res) => {
				var result = res.data;
				if (result.code == "SUCCESS") {
					this.onedata = result.data.list;
				} else {
					this.$message.error(result.message, 3);
				}
			});
		},
		newregexp(str){
			return new RegExp(str,"g");
		},
	
		handleCancel(){
			this.onemodal = false;
			this.twomodal = false;
			this.threemodal = false;
			this.fivemodal = false;
			this.sixmodal = false;
			this.sixmodalxz = false;
			this.sevenmodal = false;
			this.confirmLoading = false;
		},

		async listNew(){
			//请求缓存列表
			var storage=window.localStorage;
			var infoone = storage.getItem("one");
			var infotwo =storage.getItem("two");
			var infothree =storage.getItem("three");
			var one = JSON.parse(infoone);
			var two = JSON.parse(infotwo);
			// console.log(two);
			var three = JSON.parse(infothree);
			this.type = one.type;
			this.scene = one.scene;
			var conversion = '';//转化目标
			if(one.scene !=3){
				//查询转化目标
				var vertpage = {"filtering":[
					{"field":'id',"operator":'EQUALS',"value":two.convert_id}
				]}; 
				await ajaxparems(ADCONVERT,vertpage).then((ress)=>{
					conversion =ress.data.data;//转化目标
				})
				two = Object.assign({},two, {conversion:conversion[0]});
			}else{
				two = Object.assign({},two, {conversion:{}});
			}
			two = Object.assign({},two, {external_url:''});
			two = Object.assign({},two, {externalname:''});
			two = Object.assign({},two, {downloadname:''});
			two = Object.assign({},two, {download_url:''});

			//请求广告主
			var parems = {};
			let awlist = [];
			var name = this.name;
			if(one.scene ==3){
				//选择批量创建自定义只选择一个账户，多个广告组
				if(one.tabs =='a'){
					if(one.type ==1){
						parems = {"filtering":[
							{"field":'account_id',"operator":'EQUALS',"value":one.advertiser_id}
						]};
						await ajaxparems(ACCOUNTURL, parems).then((isv) => {
							var result = isv.data;
							if(result.code =="SUCCESS"){

								result.data.forEach(async (item,i) =>{
									var campaignlist = [];
									var vertpage = {"filtering":[
										{"field":'id',"operator":'IN',"value":one.campaignlist[i]}
									]};
									await ajaxparems(ADVER,vertpage).then((val)=>{
										var result=val.data;
										campaignlist = result.data.list;
									})

									var list = [];
									for (let i = 0; i < 3; i++) {
										var camname = campaignlist[campaignlist.length>i?i:0];
										one = Object.assign({},one, {campaignlist:camname});
										var twoname = two.audience[two.audience.length>i?i:0];
										two = Object.assign({},two, {"channe":""});
										two = Object.assign({},two, {audiencelist:twoname});
										one = Object.assign({},one, {is_check:false});
										two = Object.assign({},two, {is_check:false});
										two = Object.assign({},two, {is_checks:false});
										two = Object.assign({},two, {crowdcheck:false});
										three = Object.assign({},three, {is_check:false});

										two = Object.assign({},two, {urlcheck:false});

										var threename = three.creatives[three.creatives.length>i?i:0];
										three = Object.assign({},three, {creativeslist:threename});

										three = Object.assign({},three, {threetext:threename.name});
										two = Object.assign({},two, {twotext:twoname.name});
										
										var namelist = '';
										if(two.namelist.length >0){
											if(two.namelist.indexOf(1) !== -1){

												//定向
												namelist += `${name}${twoname.name}`;
											}
												if(two.namelist.indexOf(2) !== -1){
													namelist += `${name}${'{转化名称}'}`
											}
												if(two.namelist.indexOf(3) !== -1){
												// 创意
												namelist += `${name}${threename.name}`;
											}
												if(two.namelist.indexOf(4) !== -1){
												namelist =name+i;
											}
											console.log(namelist);
											two = Object.assign({},two, {name:namelist});
										}

										// console.log(two);
	
										list.push({
											one,
											two,
											three,
										})
									}
									awlist.push({
										account_id:item.account_id,//广告主id
										name:item.name,//广告主名称
										advercheckAll:false,
										audiencecheckAll:false,
										creativecheckAll:false,
										conversioncheckAll:false,
										crowdcheckAll:false,
										pagecheckAll:false,
										num:1,
										list,
									})
								})
							}	
						})
						console.log(awlist);
						this.datalist = [...awlist];
					}else if(one.type ==3){
						//自定义创意多个账户多个广告组
						one.list.forEach(async (res) =>{
							var campaignlist = [];
							parems = {"filtering":[
								{"field":'account_id',"operator":'EQUALS',"value":res.advertiser_id}
							]};
							await ajaxparems(ACCOUNTURL, parems).then((isv) => {
								var item = isv.data.data[0];
								if(isv.data.code =="SUCCESS"){
									var list = [];
									campaignlist = res.campaignlist;
									for (let i = 0; i < 3; i++) {
										var camname = campaignlist[campaignlist.length>i?i:0];
										one = Object.assign({},one, {campaignlist:camname});
										two = Object.assign({},two, {"channe":""});
										one = Object.assign({},one, {is_check:false});
										two = Object.assign({},two, {is_check:false});
										two = Object.assign({},two, {is_checks:false});
										two = Object.assign({},two, {crowdcheck:false});
										three = Object.assign({},three, {is_check:false});
										two = Object.assign({},two, {urlcheck:false});

										var threename = three.creatives[three.creatives.length>i?i:0];
										this.threetext = threename.name;
										three = Object.assign({},three, {creativeslist:threename});
										var twoname = two.audience[two.audience.length>i?i:0];
										this.twotext = twoname.name;
										two = Object.assign({},two, {audiencelist:twoname});

										three = Object.assign({},three, {threetext:threename.name});
										two = Object.assign({},two, {twotext:twoname.name});
										var namelist = '';
										if(two.namelist.length >0){
											if(two.namelist.indexOf(1) !== -1){
												//定向
												namelist += `${name}${twoname.name}`;
											}
											if(two.namelist.indexOf(2) !== -1){
												namelist += `${name}${'{转化名称}'}`
											}
											if(two.namelist.indexOf(3) !== -1){
												// 创意
												namelist += `${name}${threename.name}`;
											}
											if(two.namelist.indexOf(4) !== -1){
												namelist =name+i;
											}
											two = Object.assign({},two, {name:namelist});
										}
										list.push({
											one,
											two,
											three,
										})
									}
									awlist.push({
										account_id:item.account_id,//广告主id
										name:item.name,//广告主名称
										advercheckAll:false,
										audiencecheckAll:false,
										creativecheckAll:false,
										conversioncheckAll:false,
										crowdcheckAll:false,
										pagecheckAll:false,
										num:1,
										list,
									})
								}else{
									this.$message.error(isv.data.message,3);
								}
							})
						})
						console.log(awlist,"|3333");
						this.datalist = awlist ;
					}else{
						//自定义一个账户一个广告组（创建广告组）
						parems = {"filtering":[
							{"field":'account_id',"operator":'EQUALS',"value":one.advertiser_id}
						]};
						await ajaxparems(ACCOUNTURL, parems).then((isv) => {
							var result = isv.data;
							if(result.code =="SUCCESS"){

								console.log(one);
								result.data.forEach(async (item) =>{
									var campaignlist = [];
									var vertpage = {"filtering":[
										{"field":'id',"operator":'IN',"value":one.campaignlist}
									]};
									await ajaxparems(ADVER,vertpage).then((val)=>{
										var result=val.data;
										campaignlist = result.data.list;
									})

									var list = [];
									for (let i = 0; i < 3; i++) {
										var camname = campaignlist[campaignlist.length>i?i:0];
										one = Object.assign({},one, {campaignlist:camname});
										var twoname = two.audience[two.audience.length>i?i:0];

										two = Object.assign({},two, {"channe":""});
										two = Object.assign({},two, {audiencelist:twoname});
										one = Object.assign({},one, {is_check:false});
										two = Object.assign({},two, {is_check:false});
										two = Object.assign({},two, {is_checks:false});
										two = Object.assign({},two, {crowdcheck:false});
										three = Object.assign({},three, {is_check:false});
										two = Object.assign({},two, {urlcheck:false});

										var threename = three.creatives[three.creatives.length>i?i:0];
										three = Object.assign({},three, {creativeslist:threename});
										three = Object.assign({},three, {threetext:threename.name});
										two = Object.assign({},two, {twotext:twoname.name});
	
										var namelist = '';
										if(two.namelist.length >0){
											if(two.namelist.indexOf(1) !== -1){
												console.log(threename.name,"11111");
												//定向
												namelist += `${name}${twoname.name}`;
											}
												if(two.namelist.indexOf(2) !== -1){
													namelist += `${name}${'{转化名称}'}`
											}
												if(two.namelist.indexOf(3) !== -1){
												// 创意
												namelist += `${name}${threename.name}`;
											}
												if(two.namelist.indexOf(4) !== -1){
												namelist =name+i;
											}
											console.log(namelist);
											two = Object.assign({},two, {name:namelist});
										}
	
										list.push({
											// key:i+1,
											one,
											two,
											three,
										})
									}
									awlist.push({
										account_id:item.account_id,//广告主id
										name:item.name,//广告主名称
										advercheckAll:false,
										audiencecheckAll:false,
										creativecheckAll:false,
										conversioncheckAll:false,
										crowdcheckAll:false,
										pagecheckAll:false,
										num:1,
										list,
									})
								})
							}	
						})
						console.log(awlist);
						this.datalist = awlist;
					}
				}else{
					
					one.list.forEach(async (res) =>{
						var campaignlist = [];
						parems = {"filtering":[
							{"field":'account_id',"operator":'EQUALS',"value":res.advertiser_id}
						]};
						await ajaxparems(ACCOUNTURL, parems).then((isv) => {
							var item = isv.data.data[0];
							console.log(item);
							if(isv.data.code =="SUCCESS"){
								var list = [];
								campaignlist = res.campaignlist;
								for (let i = 0; i < 3; i++) {
									var camname = campaignlist[campaignlist.length>i?i:0];
									one = Object.assign({},one, {campaignlist:camname});
									two = Object.assign({},two, {"channe":""});
									var threename = three.creatives[three.creatives.length>i?i:0];
									three = Object.assign({},three, {creativeslist:threename});
									var twoname = two.audience[two.audience.length>i?i:0];
									two = Object.assign({},two, {audiencelist:twoname});
									one = Object.assign({},one, {is_check:false});
									two = Object.assign({},two, {is_check:false});
									two = Object.assign({},two, {is_checks:false});
									two = Object.assign({},two, {crowdcheck:false});
									three = Object.assign({},three, {is_check:false});
									two = Object.assign({},two, {urlcheck:false});

									three = Object.assign({},three, {threetext:threename.name});
									two = Object.assign({},two, {twotext:twoname.name});

									var namelist = '';
									if(two.namelist.length >0){
										if(two.namelist.indexOf(1) !== -1){
											//定向
											namelist += `${name}${twoname.name}`;
										}
											if(two.namelist.indexOf(2) !== -1){
												namelist += `${name}${'{转化名称}'}`
										}
											if(two.namelist.indexOf(3) !== -1){
											// 创意
											namelist += `${name}${threename.name}`;
										}
											if(two.namelist.indexOf(4) !== -1){
											namelist =name+i;
										}
										two = Object.assign({},two, {name:namelist});
									}
									list.push({
										one,
										two,
										three,
									})
								}
								awlist.push({
									account_id:item.account_id,//广告主id
									name:item.name,//广告主名称
									num:1,
									advercheckAll:false,
									audiencecheckAll:false,
									creativecheckAll:false,
									conversioncheckAll:false,
									crowdcheckAll:false,
									pagecheckAll:false,
									list,
								})
							}else{
								this.$message.error(isv.data.message,3);
							}
						})
					})
					// console.log(awlist);
					this.datalist = awlist;
				}
			}else{
				parems = {"filtering":[
					{"field":'account_id',"operator":'EQUALS',"value":one.advertiser_id}
				]};
				await ajaxparems(ACCOUNTURL, parems).then((isv) => {
					var item = isv.data.data[0];

					if(isv.data.code =="SUCCESS"){
						one = Object.assign({},one, {campaignlist:one});
						two = Object.assign({},two, {audiencelist:two.audience[0]});
						two = Object.assign({},two, {"channe":""});
						three = Object.assign({},three, {creativeslist:three.creatives[0]});

						one = Object.assign({},one, {is_check:false});
						two = Object.assign({},two, {is_check:false});
						two = Object.assign({},two, {is_checks:false});
						two = Object.assign({},two, {crowdcheck:false});
						
						three = Object.assign({},three, {is_check:false});
						two = Object.assign({},two, {urlcheck:false});

						three = Object.assign({},three, {threetext:three.creatives[0].name});
						two = Object.assign({},two, {twotext:two.audience[0].name});
						var namelist = '';
						var name = this.name;
						if(two.namelist.length >0){
							if(two.namelist.indexOf(1) !== -1){
								//定向
								namelist += `${name}${two.audience[0].name}`;
							}
							if(two.namelist.indexOf(2) !== -1){
								namelist += `${name}${two.conversion.name}`;
							}
							if(two.namelist.indexOf(3) !== -1){
								// 创意
								namelist += `${name}${three.creatives[0].name}`;
							}
							if(two.namelist.indexOf(4) !== -1){
								namelist =name+1;
							}
							console.log(namelist);
							two = Object.assign({},two, {name:namelist});
						}

						awlist.push({
							account_id:item.account_id,//广告主id
							name:item.name,//广告主名称
							num:1,
							advercheckAll:false,
							audiencecheckAll:false,
							creativecheckAll:false,
							conversioncheckAll:false,
							crowdcheckAll:false,
							pagecheckAll:false,
							list:[{
								one,
								two,
								three,
							}],
						})
					}
				})
				this.datalist = awlist;
			}
			this.dmplist();
			this.spinning = false;
		},
		
		dmplist(){
			var storage=window.localStorage;
			var infoone = storage.getItem("one");
			var one = JSON.parse(infoone);

			var advertiser_id = '';
			if(one.type ==3){
				advertiser_id = one.list[0].advertiser_id;
			}else{
				advertiser_id = one.advertiser_id;
			}
			// console.log(one);
			//查询人群包
			var dmpparems = {'select_type':1}
			ajaxrequest(advertiser_id, DMPURL,dmpparems).then((res) => {
				var dmp=res.data;
				if(dmp.code =="SUCCESS"){
					// console.log(dmp.data.custom_audience_list);
					this.allTeam = dmp.data.custom_audience_list;
				}else{
					this.$message.error(dmp.message,3);
				}
			})
		},
		advernum(n,e){
			//新增数量
			this.datalist[n].num = e;
		},
		addadver(n){
			//新增广告计划
			var num = this.datalist[n].num;
			for (let i = 0; i < num; i++) {
				let a = this.addCopy(this.datalist[n].list[0])
				this.datalist[n].list.push(a);
			}
		},
		addCopy(p,b){
			var c = b || {};
			for (let i in p) {
				if(typeof p[i] === 'object'){
					c[i] = (p[i] ===Array) ? [] :{};
					this.addCopy(p[i],c[i]);
				}else{
					c[i] = p[i];
				}
			}
			return c
		},
		onchanne(n,v,e){
			//推广渠道
			this.datalist[n].list[v].two.channe = e.target.value;
		},
		async resetbtn(){
			//重置
			this.listNew();
		},
		ondelete(n,v){
			//删除规则列表
			if(this.datalist[n].list.length <=0){
				return;
			}
			this.datalist[n].list.splice(v, 1);
		},
		ongoback(){
			// window.localStorage.removeItem("one");
			window.localStorage.removeItem("two");
			window.localStorage.removeItem("three");
			this.$router.go(-3);//返回上三层
		},
		ongobacktwo(){
			// window.localStorage.removeItem("two");
			window.localStorage.removeItem("three");
			this.$router.go(-2);//返回上二层
		},
		ongobackthree(){
			this.$router.go(-1);//返回上一层
		},
		range(start, end) {
			const result = [];
			for (let i = start; i < end; i++) {
			  result.push(i);
			}
			return result;
		},
		newtime(){
			var nowDate = new Date();
			let y = nowDate.getFullYear();
			let m = nowDate.getMonth() + 1;
			m = m < 10 ? ('0' + m) : m;
			let d = nowDate.getDate();
			d = d < 10 ? ('0' + d) : d;
			let hour = nowDate.getHours();
			hour = hour < 10 ? ('0' + hour) : hour;// 时
			let minute = nowDate.getMinutes();
			minute = minute < 10 ? ('0' + minute) : minute;// 分
			let second = nowDate.getSeconds();
			second = second < 10 ? ('0' + second) : second;// 秒
			this.nowtime = y+'-'+m+'-'+d+' '+hour+':'+minute+':'+second;
		},
		ondatatime(value, dateString) {
			console.log('Selected Time: ', value)
			this.nowtime = dateString;
			// console.log('Formatted Selected Time: ', dateString)
		},
		disabledDate(current) {
			return current && current < moment().endOf('day');
		},
		disabledDateTime() {
			return {
			  disabledHours: () => this.range(0, 24).splice(4, 20),
			  disabledMinutes: () => this.range(30, 60),
			  disabledSeconds: () => [55, 56],
			};
		},
		disabledRangeTime(_, type) {
			if (type === 'start') {
				return {
				disabledHours: () => this.range(0, 60).splice(4, 20),
				disabledMinutes: () => this.range(30, 60),
				disabledSeconds: () => [55, 56],
				};
			}
			return {
				disabledHours: () => this.range(0, 60).splice(20, 4),
				disabledMinutes: () => this.range(0, 31),
				disabledSeconds: () => [55, 56],
			};
		},
		ontoshows(e){
			this.timenum = e.target.value;
		},
		onnext(){
			this.logging = true;
			// 保存
			this.form.validateFields((err,values) => {
				if(!err){
					var dataparems = [];
					var datatime = {};
					var statusval = {};
					// 提交规则
					if(values['rule'] =="timming"){
						datatime ={
							start_at:this.nowtime
						}
					}else if(values['rule'] =="chunk"){
						datatime = {
							chunk_minute:values['chunk_minute'],
							chunk_size:values['chunk_size'],
						}
					}else if(values['rule'] =="cycle"){
						datatime ={
							cycle_minute:values['cycle_minute'],
							cycle_times:values['cycle_times']
						}
					}else{
						datatime = {};
					}
					//状态
					if(values['switch'] ==true){
						statusval = "enable";
					}else{
						statusval = "disable";
					}
					// 提交计划创意
					var item = [];
					try{
						for(let a = 0; a < this.datalist.length; a++) {
							for(let i = 0; i < this.datalist[a].list.length; i++) {
								var b = (JSON.stringify(this.datalist[a].list[i].two.conversion) == "{}");
								if(b){
									this.logging = false;
									this.$message.error('转化配置为空',3);
									throw new Error('转化配置为空');
								}

								if(this.datalist[a].list[i].two.download_type =='EXTERNAL_URL'){
									if(this.datalist[a].list[i].two.external_url ==''){
										this.logging = false;
										this.$message.error('请选择或输入落地页链接',3);
										throw new Error('请选择或输入落地页链接');
									}
									this.$delete(this.datalist[a].list[i].two,'download_url');
								}else{
									if(this.datalist[a].list[i].two.download_url ==''){
										this.logging = false;
										this.$message.error('请选择输入应用下载链接',3);
										throw new Error('请选择输入应用下载链接');
									}
									this.$delete(this.datalist[a].list[i].two,'external_url');
								}
								// console.log(this.datalist[a].list[i]);
								// var b = (JSON.stringify(this.datalist[a].list[i].two.conversion) == "{}");
								// if(this.datalist[a].list[i].two.channe ==""){
								// 	this.$message.error('请输入推广渠道',3);
								// 	break;
								// }
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {advertiser_id:this.datalist[a].account_id});//计划广告账户
								this.datalist[a].list[i].three = Object.assign(this.datalist[a].list[i].three,{advertiser_id:this.datalist[a].account_id});//创意广告账户
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {convert_id:this.datalist[a].list[i].two.conversion.id});//转化
								this.datalist[a].list[i].two = Object.assign(this.datalist[a].list[i].two, this.datalist[a].list[i].two.audiencelist.audience);//定向
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {campaign_id:this.datalist[a].list[i].one.campaignlist.id});//广告组
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {operation:statusval});//计划状态
								this.datalist[a].list[i].three = Object.assign({},this.datalist[a].list[i].three, {opt_status:statusval});//创意状态
								this.datalist[a].list[i].three = Object.assign(this.datalist[a].list[i].three,{creatives:this.datalist[a].list[i].three.creativeslist.crearr});//创意
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {name:this.datalist[a].list[i].two.name+this.datalist[a].list[i].two.channe});//计划名称
								
								this.datalist[a].list[i].two = Object.assign({},this.datalist[a].list[i].two, {action_scene:['E-COMMERCE','NEWS','APP']});//行为场景
								item.push({
									"account_id":this.datalist[a].account_id,
									"ad":this.datalist[a].list[i].two,
									"creative":this.datalist[a].list[i].three
								})
							}
						}

						// console.log(item);
						// console.log(ALLCREATE);
						// console.log(datatime);
						// console.log(dataparems);

						dataparems = {"rule":values['rule'],rule_option:datatime,items:item}
						ajaxparems(ALLCREATE,dataparems).then((res)=>{
							var result=res.data;
							if(result.code =="SUCCESS"){
								this.logging = false;
								window.localStorage.removeItem("one");
								window.localStorage.removeItem("two");
								window.localStorage.removeItem("three");

								this.$message.success(result.message, 3).then(
									this.$router.push('/promotion/batchtask')
								);
								this.reload();
							}else{
								this.logging = false;
								this.$message.error(result.message,3);
								return;
							}
						})
					}catch(e){
						this.logging = false;
						console.log(e.message);
						this.$message.error(e.message,3);
					}
				}else{
					this.logging = false;
				}
			});
		}
	},
	computed: {
		...mapGetters('account', ['user']),
	}
};